public class Solution {
    public String minWindow(String s, String t) {
        char[] s1 = s.toCharArray();
        char[] t1 = t.toCharArray();
        //存目标元素信息
        int[] hash1 = new int[128];
        int kinds = 0; //目标字符种类
        for (char ch : t1) {
            if (hash1[ch] == 0)
                kinds++;
            hash1[ch]++;
        }
        int len = Integer.MAX_VALUE, begin = -1;
        int[] hash2 = new int[128];
        //滑动窗口
        for (int left = 0, right = 0, count = 0; right < s1.length; right++) {
            //入窗口
            char in = s1[right];
            hash2[in]++;
            //判断count
            if (hash1[in] == hash2[in])
                count++;
            //判断
            while (count == kinds) {
                //更新
                if (right - left + 1 < len) {
                    len = right - left + 1;
                    begin = left;
                }
                //出窗口
                char out = s1[left];
                //判断count
                if (hash1[out] == hash2[out])
                    count--;
                hash2[out]--;
                left++;
            }
        }
        if (begin == -1)
            return "";
        else
            return s.substring(begin, begin + len);
    }
}
